using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Mani.Common;
using Ghasam.Business.Services;
using Ghasam.Business.Domain.Entity;

public partial class EditCheque : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) {
            LoadPayment();
        }
    }
    private IPaymentService paymentService;
    private ICustomerService customerService;
    private int _isFormal;


    public IPaymentService PaymentService
    {
        get { return paymentService; }
        set { paymentService = value; }
    }
    private int paymentId
    { get { return Convert.ToInt32(Request.QueryString["paymentId"]); } }
    private void LoadPayment() {

        PaymentCheque paymentCheq = paymentService.PaymentFindById(paymentId);
            txtCustomerName.Text = paymentCheq.Customer.CustomerName;
            txtChequeNumber.Text = paymentCheq.ChequeNumber;
            txtBankName.Text = paymentCheq.BankName;
            txtBranchName.Text = paymentCheq.BankBranch;
            txtAmount.Text = paymentCheq.Amount.ToString();

            txtChequeDate.Text = MyPersianDate.DateTimeToPersian(paymentCheq.ChequeDate);
            txtPaidDate.Text = MyPersianDate.DateTimeToPersian(paymentCheq.PaidTo);
            txtChequeReceive.Text = MyPersianDate.DateTimeToPersian(paymentCheq.ChequeDate);

            txtComment.Text =paymentCheq.Comment;
            txtPaidTo.Text =paymentCheq.PaidTo;
       
    }

    protected void btnSave_Click( object sender, EventArgs e ) {
        int paymentId = Convert.ToInt32( Request.QueryString["paymentId"] );
        DateTime paidDate = new DateTime();
        if (!String.IsNullOrEmpty(txtPaidDate.Text)) {
            paidDate = MyPersianDate.PersianToDateTime( txtPaidDate.Text );
        }
        PaymentService.PaymentChequeUpdate(paymentId, txtPaidTo.Text, paidDate, txtComment.Text, DateTime.Now.Date);
        Response.Redirect( "ChequeList.aspx" );
    }
}
